package com.longjianghuasheng.logistics.business.mine.viewmodel

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.RegexUtils
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.checkPhone
import com.longjianghuasheng.logistics.ext.commit2
import com.longjianghuasheng.logistics.ext.judge
import com.longjianghuasheng.logistics.ext.toastNormal
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine

class PersonalInformationViewModel : BaseMultiStateViewModel() {
    var real_name: String = ""
    var sex: Int = 0
    var tel: String = ""
    var card_no: String = ""
    var card_front: String = ""
    var card_back: String = ""

    val notify by lazy {

        MutableLiveData<ApiResponseNoData>()
    }


    fun person_info() {

        var isSuccess = false
        when {
            real_name.judge("请输入姓名") -> {}
            sex == 0 -> toastNormal("请选择性别")
            !checkPhone(tel) -> {}
            card_no.judge("请输入身份证号") -> {}
            !RegexUtils.isIDCard18(card_no) -> toastNormal("身份证号有误")
            card_front.judge("请上传身份证正面") -> {}
            card_back.judge("请上传身份证背面") -> {}

            else -> isSuccess = true
        }

        if (!isSuccess) return




        commit2({
            HttpRequestCoroutine.person_info(
                real_name,
                sex,
                tel,
                card_no,
                card_front,
                card_back
            )
        }, notify)
    }

}